package cn.edu.nuc.ssm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.ssm.controller.page.PageControl;
import cn.edu.nuc.ssm.controller.page.Pager;
import cn.edu.nuc.ssm.controller.page.Pc;
import cn.edu.nuc.ssm.dao.TypeMapper;
import cn.edu.nuc.ssm.domain.Type;
import cn.edu.nuc.ssm.service.interfaces.TypeService;
@Service
public class TypeServiceImpl implements TypeService {
    @Autowired
	private TypeMapper mapper;
    //添加一个影片类型
	@Override
	public int insert(Type type) {
		return mapper.insert(type);
	}
	//后台分页显示影片类型信息
	@Override
	public Pager<Type> pageList(String typename, int current) {
		PageControl pc = new PageControl();
		Integer currindex = 1;
		if(current != 0){
			currindex = current;
		}
		pc.setCurrentindex(currindex);
		
		//查询总记录数。(如果带有名字，则查询改名字的总记录数。(模糊查询)
		int count = mapper.count("%"+typename+"%");
		pc.setRscount(count);
		//初始化分页参数。
		pc = Pc.dealpage(pc);
		//查询具体内容
		List<Type> type = mapper.selectType("%"+typename+"%",(pc.getCurrentindex()-1)*pc.getPagesize(),
				pc.getCurrentindex()*pc.getPagesize());
		Pager<Type> pager = new Pager<Type>();
		pager.setList(type);
		pager.setPagectrl(pc);
		return pager;
	}
	//通过影片类型id查询影片类型信息
	@Override
	public Type selectByFtid(Integer ftid) {
		return mapper.selectByPrimaryKey(ftid);
	}
	//更新影片类型信息
	@Override
	public int updateByPrimaryKey(Type type) {
		return mapper.updateByPrimaryKey(type);
	}
	//通过主键删除单个影片类型信息。
	@Override
	public int deleteByPrimaryKey(Integer ftid) {
		return mapper.deleteByPrimaryKey(ftid);
	}

}
